package com.ruoyi.oss.factory;

import com.ruoyi.common.utils.spring.SpringUtils;
import com.ruoyi.oss.constant.OssConstant;
import com.ruoyi.oss.properties.OSSProperties;
import com.ruoyi.oss.service.IOssStrategy;
import com.ruoyi.oss.service.impl.MinioOssStrategy;
import org.checkerframework.checker.units.qual.A;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Service;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 创建对象存储服务的工厂
 * @author 最爱喝兽奶
 * @create 2022/6/13
 **/
@Service
public class OssFactory {


    private static final Logger logger = LoggerFactory.getLogger(OssFactory.class);

    private static OSSProperties ossProperties;

    private static MinioOssStrategy strategy = null;

    public static void init() {
        try {
            ossProperties = SpringUtils.getBean(OSSProperties.class);
            logger.info("初始化成功");
        } catch (Exception e) {
            logger.error("初始化失败");
        }
    }

    public static IOssStrategy instance() {
        // TODO: 还没想好怎么写工厂，先拉跨一下
        if (null == strategy) {
            init();
            strategy = new MinioOssStrategy();
            strategy.init(ossProperties);
        }
        return strategy;
    }


}
